package com.cheer.controller;

import com.cheer.common.Page;
import com.cheer.common.Result;
import com.cheer.security.UserInfoHolder;
import com.cheer.service.ExPresentAudioAdminService;
import com.cheer.vo.*;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/present/audio")
public class ExPresentAudioController {

    @Autowired
    private ExPresentAudioAdminService exPresentAudioAdminService;

    @Autowired
    private UserInfoHolder userInfoHolder;

    @ApiOperation("参与总人数")
    @GetMapping("/statistics")
    public Result<ExPresentAudioStatisticsAdminVO> statistics() {
        return Result.success(exPresentAudioAdminService.getStatistics(userInfoHolder.getAdmin().getPid()));
    }

    @ApiOperation("查询单位列表")
    @GetMapping("/list")
    public Result<Page<ExPresentAudioLearnClassVO>> list(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                         @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                         @RequestParam(required = false) Integer id) {
        if (id == null) {
            id = userInfoHolder.getAdmin().getPid();
        }
        return Result.success(exPresentAudioAdminService.list(pageNum, pageSize, id));
    }

    @ApiOperation("查询单位")
    @GetMapping("/info")
    public Result<ExPresentAudioLearnClassInfoVO> info(@RequestParam Integer id) {
        return Result.success(exPresentAudioAdminService.info(id));
    }

    @ApiOperation("查询用户列表")
    @GetMapping("/user/list")
    public Result<Page<ExPresentAudioUserVO>> userList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                       @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                       @RequestParam Integer id, @RequestParam(required = false) String name) {
        return Result.success(exPresentAudioAdminService.userList(pageNum, pageSize, id, name));
    }

    @ApiOperation("删除")
    @GetMapping("/user/delete")
    public Result delete(@RequestParam Integer id) {
        exPresentAudioAdminService.delete(id);
        return Result.success();
    }

    @ApiOperation("批量删除")
    @PostMapping("/user/delete")
    public Result delete(@RequestBody List<Integer> ids) {
        for (Integer id : ids) {
            exPresentAudioAdminService.delete(id);
        }
        return Result.success();
    }

    @ApiOperation("查询用户")
    @GetMapping("/user")
    public Result<ExPresentAudioUserAdminVO> user(@RequestParam Integer id) {
        ExPresentAudioUserAdminVO exPresentAudioUserAdminVO = exPresentAudioAdminService.user(id);
        return Result.success(exPresentAudioUserAdminVO);
    }

    @ApiOperation("查询审核列表")
    @GetMapping("/audio/list")
    public Result<Page<ExPresentAudioAdminVO>> audio(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                     @RequestParam(required = false, defaultValue = "10") Integer pageSize,
                                                     @RequestParam Integer id) {
        Page<ExPresentAudioAdminVO> page = exPresentAudioAdminService.audio(pageNum, pageSize, id);
        return Result.success(page);
    }

    @ApiOperation("删除")
    @GetMapping("/audio/delete")
    public Result deleteAudio(@RequestParam Integer id) {
        exPresentAudioAdminService.deleteAudio(id);
        return Result.success();
    }

    @ApiOperation("删除")
    @PostMapping("/audio/delete")
    public Result deleteAudio(@RequestBody List<Integer> ids) {
        for (Integer id : ids) {
            exPresentAudioAdminService.deleteAudio(id);
        }
        return Result.success();
    }

    @ApiOperation("审核")
    @GetMapping("/review")
    public Result review(@RequestParam Integer id, @RequestParam Integer status) {
        exPresentAudioAdminService.review(id, status);
        return Result.success();
    }

    @ApiOperation("详情")
    @GetMapping("/audio/info")
    public Result<ExPresentAudioAdminVO> audioInfo(@RequestParam Integer id) {
        ExPresentAudioAdminVO vo = exPresentAudioAdminService.audioInfo(id);
        return Result.success(vo);
    }

    @ApiOperation("查询待审核列表")
    @GetMapping("/audio/unreview/list")
    public Result<Page<ExPresentAudioAdminVO>> unreviewList(@RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                                            @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        Page<ExPresentAudioAdminVO> page = exPresentAudioAdminService.unreviewList(pageNum, pageSize, userInfoHolder.getAdmin().getPid());
        return Result.success(page);
    }

    @ApiOperation("详情")
    @GetMapping("/audio/unreview/info")
    public Result<ExPresentAudioAdminVO> unreviewInfo(@RequestParam Integer id) {
        ExPresentAudioAdminVO vo = exPresentAudioAdminService.unreviewInfo(id);
        return Result.success(vo);
    }

}
